package com.njegovanobradovic.pages;

import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.ioc.annotations.Inject;

import com.njegovanobradovic.entities.Page;
import com.njegovanobradovic.so.GetAll;
import com.njegovanobradovic.so.GetHomePage;

/**
 * Start page of application cms.
 */
public class Index{
    @Persist
    private Page page;
    @Inject
    private GetHomePage getHomePage;
    @Inject
    private GetAll<Page> getAllPages;
    
    public Page getPage() {
		return page;
	}
	public void setPage(Page page) {
		this.page = page;
	}

	public boolean isDbHaveData(){
    	if (getAllPages.execute().size()==0) {
			return false;
		}
    	return true;
    }
	
	public void onActivate(){
		getAllPages.setSearchForType(Page.class);
		if (getPage()==null && isDbHaveData()) {
			setPage(getHomePage.execute());
		}
	}
    
}
